
//
//  TSRegisterVC.m
//  tristana
//
//  Created by bug neo on 05/01/2021.
//  Copyright © 2021 李康. All rights reserved.
//

#import "TSRegisterVC.h"

#import "TSToast.h"

#import "UITextField+inputs.h"

@interface TSRegisterVC ()
@property (weak, nonatomic) IBOutlet UIButton *timeBtb;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, assign) NSInteger backTime;
@property (nonatomic, assign) BOOL isStart;
@property (weak, nonatomic) IBOutlet UITextField *codeField;
@end

@implementation TSRegisterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initAllPropertys];
}

- (void)dealloc
{
    NSLog(@"%s",__func__);
}
- (void)initAllPropertys {
    self.backTime = 60;
    self.isStart = NO;
}

- (void)setupUI {
    
}
- (IBAction)clickBack:(id)sender {
    [self.timer invalidate];
    self.timer = nil;
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)clickRegister:(id)sender {
    NSLog(@"请输入正确验证码");
    if (self.codeField.text.length == 0) {
        [TSToast toast:@"请输入验证码"];
    }else {
        [TSToast toast:@"验证码不正确"];
    }
    
}
- (IBAction)getCode:(id)sender {
    if (self.isStart) {
        return;
    }
    self.isStart = YES;
    __weak __typeof__(self) weakSelf = self;

    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
        
        weakSelf.backTime --;
        if (weakSelf.backTime<0) {
            self.isStart = NO;
            self.backTime = 60;
            [weakSelf.timer invalidate];
            weakSelf.timer = nil;
            [weakSelf.timeBtb setTitle:@"重试" forState:UIControlStateNormal];
            return;
        }
        [weakSelf.timeBtb setTitle:[NSString stringWithFormat:@"%lds后重试",self.backTime] forState:UIControlStateNormal];
    }];
    
    
}

@end
